#pragma once
#include <iostream>
#include <functional>
#include<cstdio>
using namespace std;
void ServerIO(int sock)
    {
        char buffer[1024];
        while (1)
        {
            ssize_t n = read(sock, buffer, sizeof buffer);
            if (n < 0)
            {
                //logMessage(FATAL, "read error");
                cout<<"read error"<<endl;
                exit(2);
            }
            else if (n == 0)
            {
                cout << "Clent quit me too" << endl;
                break;
            }
            // 转发给客户端
            buffer[n] = 0;
            string message = "recv message :";
            message += buffer;
            cout << message << endl;
            int i = write(sock,buffer,strlen(buffer));
            if (i < 0)
            {
                //logMessage(FATAL, "Server write error");
                cout<<"server write error"<<endl;
                exit(2);
            }
        }
    }
class Task
{
public:
    using func_t = function<void(int)>;
    Task(int sock,func_t func):_func(func),_sock(sock)
    {}
    Task()
    {}
    void operator()()
    {
        _func(_sock);
    }
private:
    int _sock;
    func_t _func;
};
